package com.jy.wms.controller;

import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.WmsPoEnclosure;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsSoEnclosure;
import com.jy.wms.service.WmsSoEnclosureService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.ArrayList;
import java.util.List;
import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsSoEnclosureController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author LH
 * @Date Tue Dec 26 14:04:27 GMT+08:00 2017
 */
@RestController
@RequestMapping("/wmssoenclosure")
@Api(value = "/wmssoenclosure", description = "关于发运订单附件操作")
public class  WmsSoEnclosureController extends BaseController<WmsSoEnclosureService,WmsSoEnclosure> {

    @ApiOperation(value = "发运订单附件管理 发运订单附件列表", response = JSONObject.class, notes = "查询发运订单附件列表")
    @GetMapping(value = "/list/{soid}")
    public @ResponseBody JSONArray list(@PathVariable("soid") String soid) {
        List<WmsPoEnclosure> list = new ArrayList<WmsPoEnclosure>();
        JSONArray json = new JSONArray();
        try {
            json = JSONArray.fromObject(baseService.getListBySoid(soid));
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    @ApiOperation(value = "发运订单附件管理 新增发运订单附件",response = JSONObject.class, notes = "新增发运订单附件")
    @PostMapping(value = "/add")
    public @ResponseBody
    JSONObject save(@RequestBody WmsSoEnclosure entity){
        try {
            baseService.baseInsertSelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"新增发运订单附件成功","", JSONObject.fromObject(entity).toString());
        } catch (SucessException e) {
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"新增发运订单附件成功",e.getMessage(),JSONObject.fromObject(entity).toString());
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"新增发运订单失败",e.getMessage(),"");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"新增发运订单失败",e.getMessage(),"");
        }
    }

    @ApiOperation(value = "发运订单附件管理 修改发运订单附件",response = JSONObject.class, notes = "修改发运订单附件")
    @PutMapping(value = "/edit")
    public @ResponseBody
    JSONObject edit(@RequestBody WmsSoEnclosure entity){
        try {
            baseService.baseUpdateByPrimaryKeySelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"修改发运订单附件成功","", "");
        } catch (SucessException e) {
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"修改发运订单附件成功",e.getMessage(),"");
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"修改发运订单失败",e.getMessage(),"");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"修改发运订单失败",e.getMessage(),"");
        }
    }

    @ApiOperation(value = "发运订单附件管理 批量删除发运订单附件",response = JSONObject.class, notes = "批量删除发运订单附件")
    @PostMapping(value = "/del")
    public @ResponseBody
    JSONObject del(@RequestBody SetAndModifyModel setAndModifyModel){
        try {
            baseService.baseDeleteBathPrimaryKeys(setAndModifyModel.getIds());
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"删除发运订单附件成功","", "");
        } catch (SucessException e) {
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"删除发运订单附件成功",e.getMessage(),"");
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"删除发运订单失败",e.getMessage(),"");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"删除发运订单失败",e.getMessage(),"");
        }
    }
}
